package control

import "fmt"

// 普通用法 for init; condition;post {}
// while for condition {}
// 死循环 for {}

func runFor() {

	// 普通用法 for init; condition;post {}

	//多个变量，只能使用平行赋值，不能用i++,j++
	for i, j := 1, 10; i < j; i, j = i+1, j-1 {
		fmt.Println(i)
	}

	//while for condition {}
	fmt.Println("for range begin")
	for _, value := range "Go在中国" {
		// fmt.Printf("%s",value)
		// fmt.Printf("character '%c' type is %T value is %v, and start at byte position %d \n", value,value,value, pos)
		// str :=string(value)  //convert rune to string
		fmt.Printf("string(%v)=>%c \n", value, value)
	}

	//死循环 for {}
	sum := 0
	for {
		if sum > 10 {
			break
		}
		sum += 2
	}

	sum = 0
myforLable:
	for {
		for i := 0; i < 10; i++ {
			if sum > 200 {
				break myforLable //将退出循环体for{}
			}
			sum += i
		}
	}
	fmt.Println(sum)
}
